home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / WIN / VB_SYS / PATH_VB.ZIP / PATH.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1993-09-08  |  4.7 KB  |  131 lines

  1. VERSION 2.00
  2. Begin Form frmMain 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "Display Program Directory"
  5.    ClientHeight    =   3180
  6.    ClientLeft      =   5925
  7.    ClientTop       =   2235
  8.    ClientWidth     =   6255
  9.    Height          =   3585
  10.    Left            =   5865
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   3180
  13.    ScaleWidth      =   6255
  14.    Top             =   1890
  15.    Width           =   6375
  16.    Begin CommandButton cmdClose 
  17.       Caption         =   "Close"
  18.       Height          =   435
  19.       Left            =   2415
  20.       TabIndex        =   2
  21.       Top             =   2415
  22.       Width           =   1485
  23.    End
  24.    Begin Label Label1 
  25.       Alignment       =   2  'Center
  26.       BackColor       =   &H00008000&
  27.       Caption         =   "Version 1.0, 09/08/93 Comments to Sven Schreiber CIS 100115,2260"
  28.       Height          =   645
  29.       Left            =   1785
  30.       TabIndex        =   5
  31.       Top             =   1575
  32.       Width           =   2745
  33.       WordWrap        =   -1  'True
  34.    End
  35.    Begin Label lblPathText 
  36.       Alignment       =   1  'Right Justify
  37.       BackColor       =   &H00C0C0C0&
  38.       Caption         =   "Program directory:"
  39.       Height          =   225
  40.       Left            =   210
  41.       TabIndex        =   4
  42.       Top             =   945
  43.       Width           =   1590
  44.    End
  45.    Begin Label lblProgramText 
  46.       Alignment       =   1  'Right Justify
  47.       BackColor       =   &H00C0C0C0&
  48.       Caption         =   "EXE filename:"
  49.       Height          =   225
  50.       Left            =   525
  51.       TabIndex        =   3
  52.       Top             =   630
  53.       Width           =   1275
  54.    End
  55.    Begin Label lblExe 
  56.       BackColor       =   &H00C0C0C0&
  57.       Caption         =   "EXE name"
  58.       Height          =   225
  59.       Left            =   1995
  60.       TabIndex        =   1
  61.       Top             =   630
  62.       Width           =   4005
  63.    End
  64.    Begin Label lblPath 
  65.       BackColor       =   &H00C0C0C0&
  66.       Caption         =   "directory"
  67.       Height          =   225
  68.       Left            =   1995
  69.       TabIndex        =   0
  70.       Top             =   945
  71.       Width           =   4005
  72.    End
  73. Option Explicit
  74. ' This form contains two (general) functions which can
  75. ' be easily transfered to a global module or another
  76. ' form.
  77. ' Please remember to copy the following declarations as well.
  78. ' While in the VB programming environment the functions
  79. ' will only return the path of VB.
  80. ' These two functions are needed to get the neccessary
  81. ' information.
  82. Declare Function GetWindowWord Lib "User" (ByVal hWnd As Integer, ByVal nIndex As Integer) As Integer
  83. Declare Function GetModuleFileName Lib "Kernel" (ByVal hModule As Integer, ByVal lpFilename As String, ByVal nSize As Integer) As Integer
  84. ' The GetModuleFileName Function is the most important.
  85. ' It returns the full path (including) the filename
  86. ' of the applications whose handle is passed as an argument
  87. ' As VB does not provide an instance handle the GetWindowWord
  88. ' Function is needed.
  89. Sub cmdClose_Click ()
  90.    End
  91. End Sub
  92. Sub Form_Load ()
  93.     ' Display the two labels
  94.     lblExe.Caption = GetExeFileName((frmMain.hWnd))
  95.     lblPath.Caption = GetProgramDirectory((frmMain.hWnd))
  96. End Sub
  97. ' The argument hWnd is the handle of the form
  98. Function GetExeFileName (hWnd As Integer) As String
  99.    ' Needed as an argument to the GetWindowWord function
  100.    Const GWW_HINSTANCE = (-6)
  101.    ' Just good programming practice
  102.    Const MAX_PATH_LENGTH = 128
  103.    ' Buffer for the filename
  104.    Dim FileName As String * MAX_PATH_LENGTH
  105.    Dim Chars As Integer
  106.    ' Chars contains the number of returned characters
  107.    Chars = GetModuleFileName(GetWindowWord(hWnd, GWW_HINSTANCE), FileName, MAX_PATH_LENGTH)
  108.    ' Extract the filename
  109.    Do While ((Chars > 0) And Mid$(FileName, Chars, 1) <> "\")
  110.       Chars = Chars - 1
  111.    Loop
  112.    GetExeFileName = Trim$(Right$(FileName, Len(FileName) - Chars))
  113. End Function
  114. ' The argument hWnd is the handle of the form
  115. Function GetProgramDirectory (hWnd As Integer) As String
  116.    ' Needed as an argument to the GetWindowWord function
  117.    Const GWW_HINSTANCE = (-6)
  118.    ' Just good programming practice
  119.    Const MAX_PATH_LENGTH = 128
  120.    ' Buffer for the filename
  121.    Dim FileName As String * MAX_PATH_LENGTH
  122.    Dim Chars As Integer
  123.    ' Chars contains the number of returned characters
  124.    Chars = GetModuleFileName(GetWindowWord(hWnd, GWW_HINSTANCE), FileName, MAX_PATH_LENGTH)
  125.      ' Extract the directory
  126.    Do While ((Chars > 0) And Mid$(FileName, Chars, 1) <> "\")
  127.       Chars = Chars - 1
  128.    Loop
  129.    GetProgramDirectory = Left$(FileName, Chars)
  130. End Function
  131.